package cn.tedu.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

//
//
//
//
public class Sever {
    public static void main(String[] args) throws IOException {
        //1 启动服务器----参数是指端口号0-65535
        // SeverSocket(int port)
        ServerSocket sever = new ServerSocket(8000);
        System.out.println("服务器已启动");
        //接收客户端发来的连接请求
        Socket socket = sever.accept();
        System.out.println("服务器接收到一个请求");
        //TODO 3 读取客户端发来的数据
        InputStream in = socket.getInputStream();
        //read()默认返回的是int值
//        int data = in.read();
//        char c = (char)data;
//        System.out.println(c);
//        int data2 = in.read();
//        char c2 = (char)data2;
//        System.out.println(c2);
        for (int i = 0; i <5 ; i++) {
            int data=in.read();
            char c = (char)data;
            System.out.print(c);
        }
        OutputStream out = socket.getOutputStream();
        out.write("world".getBytes());
        out.close();

    }
}
